<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Http\Requests\UserRequest;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

class UserController extends Controller
{
    public function register(UserRequest $request)
    {
        $params = $request->all();
        $params['register_ip'] = $request->getClientIp();
        $params['nickname'] = '用户_' . substr($params['phone'], -4);
        $user = User::create($params);
        return apiResponse(data: $user);
    }

    /**
     * 更新用户信息
     */
    public function update(Request $request){
        $user = $request->user();
        $user->update($request->all());
        return apiResponse(data: $user);
    }
}
